# -*- coding:utf-8 -*-
"""
@File : serialportDemo

@Author: 爸爸

@Date : 2019-10-09

@Desc : 学习串口通信的demo

"""
import serial
import serial.tools.list_ports


def main():
    # port_list = serial.tools.list_ports.comports() # 当前可用串口列表
    # print(port_list)
    # ss = [0x30, 0x09, 0x31, 0x38, 0x2e, 0x35, 0x09, 0x30, 0x2e, 0x30, 0x09, 0x30, 0x09, 0x36, 0x09, 0x30, 0x0d, 0x0a,
    #       0x00]
    # s = ''
    # for i in ss:
    #     print(i, chr(i))
    #     s = s + chr(i)
    # print(s)
    # print(ss.__len__())
    ss = [0, 185, 0, 0, 6, 0]
    s = ""
    for i in ss:
        print(i, hex(i))
        s = s + '{:04x}'.format(i)
    print(s)
    ss = [s[i:i + 4] for i in range(0, len(s), 4)]
    print(ss)
    pass


if __name__ == '__main__':
    main()
    pass

